package com.raja.servingStation.service.impl;

import com.alibaba.fastjson.JSONObject;
import com.raja.servingStation.common.constant.Constants;
import com.raja.servingStation.common.constant.MysqlPageVo;
import com.raja.servingStation.dao.NoticeViewDao;
import com.raja.servingStation.dao.ServingStationDao;
import com.raja.servingStation.entity.ServingStation;
import com.raja.servingStation.entity.vo.NoticeView;
import com.raja.servingStation.service.ServingStationService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 维修站
 * Created by liuyanjun
 * on 2017/9/30/030.
 */
@Service
public class ServingStationServiceImpl implements ServingStationService {
    private static final Logger log = LoggerFactory.getLogger(ServingStationServiceImpl.class);
    @Autowired
    private ServingStationDao servingStationDao;

    @Override
    public MysqlPageVo queryStationListByPage(JSONObject body) throws Exception {
        Integer pageSize = body.getInteger("pageSize");
        Integer currPage = body.getInteger("currPage");
        MysqlPageVo mysqlPageVo = new MysqlPageVo();
        if (pageSize == null)
            pageSize = Constants.pageSize;
        mysqlPageVo.setPageSize(pageSize, currPage);
        int count = servingStationDao.cntStationList(body).intValue();
        mysqlPageVo.setTotal(count);
        if (count > 0) {
            List<ServingStation> servingStations = servingStationDao.queryStationListByPage(body, mysqlPageVo);
            mysqlPageVo.setData(servingStations);
        }
        return mysqlPageVo;
    }





    @Override
    public List<ServingStation> queryServingStations() throws Exception {
        List<ServingStation> servingStations = servingStationDao.queryStations();
        return servingStations;
    }
    @Override
    public ServingStation getUserByLoginName(String loginName) throws Exception {
        return servingStationDao.getUserByLoginName(loginName);
    }

    @Override
    public ServingStation getUserByUserId(Integer userId) throws Exception {
        return servingStationDao.getUserByUserId(userId);
    }

    @Override
    public void updateFirstPassword(ServingStation userInfo) throws Exception {
         servingStationDao.updateFirstPassword(userInfo);
    }

    @Override
    public ServingStation getUserByIdAndPassword(Integer userId, String oldPassword) throws Exception {
        return servingStationDao.getUserByIdAndPassword(userId,oldPassword);
    }
}
